package fr.ece.ing4.si.MonteCarlo.Application;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Map;
import java.util.HashMap;

public class FileOpener
{
	
	public static Map<String, Config> readFile(String FILE) throws IOException
	{
		final BufferedReader reader = new BufferedReader(new FileReader(FILE));

		final Map<String, Config> options = new HashMap<String, Config>();

		String line;
		
		for(int i=0; i<11; i++) reader.readLine(); // File header
		
		while ((line = reader.readLine()) != null)
		{
			final String[] lineArguments = line.split(";");
			
			final String name;
			final Config arguments = new Config();
			
			name = lineArguments[0];
			arguments.CallPutFlag = lineArguments[1];
			arguments.Price_S = Double.parseDouble(lineArguments[2]);
			arguments.StrikePrice_X = Double.parseDouble(lineArguments[3]);
			arguments.InterestRate_r = Double.parseDouble(lineArguments[4]);
			arguments.TimeToMaturity_T = Double.parseDouble(lineArguments[5]);
			arguments.CarryRateCost_b = Double.parseDouble(lineArguments[6]);
			arguments.UnderlyingAssetVolatility_v = Double.parseDouble(lineArguments[7]);
			arguments.nSteps = Integer.parseInt(lineArguments[8]);
			arguments.nSimulations = Integer.parseInt(lineArguments[9]);

			options.put(name, arguments);
		}

		reader.close();
		return options;
	}
	
	
}
